/**
 * 3*3的字符矩阵，要求每一行每一列恰好有一个`dfs`
 * 问最少要改几个字母？
 * 枚举一下即可，一共只有3种可能
 */
#include <bits/stdc++.h>
using namespace std;

#include <bits/extc++.h>

using llt = long long;
using vi = vector<int>;
using pii = pair<int, int>;

vector<string> A;

int proc0(){
    int ans = 0;
    if('d' != A[0][0]) ++ans;
    if('f' != A[0][1]) ++ans;
    if('s' != A[0][2]) ++ans;
    if('f' != A[1][0]) ++ans;
    if('s' != A[2][0]) ++ans;
    return ans;
}

int proc1(){
    int ans = 0;
    if('d' != A[1][0]) ++ans;
    if('f' != A[1][1]) ++ans;
    if('s' != A[1][2]) ++ans;
    if('d' != A[0][1]) ++ans;
    if('s' != A[2][1]) ++ans;
    return ans;
}

int proc2(){
    int ans = 0;
    if('d' != A[2][0]) ++ans;
    if('f' != A[2][1]) ++ans;
    if('s' != A[2][2]) ++ans;
    if('d' != A[0][2]) ++ans;
    if('f' != A[1][2]) ++ans;
    return ans;
}

int proc(){
    int ans = 6;
    ans = min(ans, proc0());
    ans = min(ans, proc1());
    ans = min(ans, proc2());
    return ans;
}

int main(){
#ifndef ONLINE_JUDGE
    freopen("z.txt", "r", stdin);
#endif
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int nofkase = 1; 
    // cin >> nofkase;
    while(nofkase--){
        A.assign(3, "");
        for(auto & s : A) cin >> s;
        cout << proc() << endl; 
    }
    return 0;
}